# -*- mode: ruby -*-
# vi: set ft=ruby :
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox'

Vagrant.configure("2") do |config|
  config.vm.box = "centos7.4"
  config.vm.box_url = "http://cloud.centos.org/centos/7/vagrant/x86_64/images/CentOS-7-x86_64-Vagrant-1708_01.VirtualBox.box"

=begin
 官方包http://cloud.centos.org/centos/7/vagrant/x86_64/images/默认启动后
 虚拟机下的/home/vagrant/.ssh/authorized_keys 这个证书配套的是当前运行目录下的
 .vagrant/machines/kubesphere-dev/virtualbox/private_key这个私钥

 因此将这个导出为新的box时，将这个私钥配套、并打开如下的注释使用即可正常登录
=end
  #使用这个box时的ssh设置例子
  #config.ssh.private_key_path = ["private_key"]
  #config.ssh.forward_agent = true
  #config.ssh.insert_key = false

  config.vm.define "dev" do |node|
        node.vm.network "private_network", ip: "192.168.99.10", adapter: 1
        node.vm.hostname = "dev"
=begin
        #默认的是rsync，这个对于大文件的话直接占用这个vm的磁盘空间，速度慢
        https://github.com/hashicorp/vagrant/issues/7157
        
        #virtualbox下共享文件的模式：虚拟机需要安装guest additions包[[kubesphere-dev] GuestAdditions 6.1.12 running --- OK.],且能看到如下的驱动
        lsmod |grep vbox
        vboxsf                 81052  1 
        vboxguest             349020  2 vboxsf

        没有的使用： modprobe vboxsf 可以加载也表示驱动已经有，只是没有加载到内核

    vagrant up时共享主机目录的输出信息
    ==> kubesphere-dev: Mounting shared folders...
        kubesphere-dev: /vagrant => /opt/work/devops/kubesphere/offline  
    如果不是共享文件，拷贝的方式的话是这个
    ==> kubesphere-dev: Rsyncing folder: /opt/work/devops/kubesphere/offline/ => /vagrant

    共享目录的挂载正常输出如下
    $ mount |grep vboxsf
    vagrant on /vagrant type vboxsf (rw,nodev,relatime,iocharset=utf8,uid=1000,gid=1000)
=end
      #node.vm.synced_folder '/hdd/test/kubesphere-all-offline-v2.1.1', '/vagrant', type: "virtualbox"

        node.vm.provider :virtualbox do |vb|
        #设置eth0为设置的自己的IP,vagrant默认是作为NAT网络使用的，防止一些服务绑定eth0出错的情况
          vb.customize ['modifyvm',:id, '--nic1', 'hostonly', '--nic2', 'nat'] # swap the networks around
          vb.customize ['modifyvm',:id, '--natpf2', "ssh,tcp,127.0.0.1,5222,,22" ] #port forward
          vb.customize ['modifyvm',:id, '--macaddress1', 'auto' ]
	        vb.customize ['modifyvm',:id, '--macaddress2', "auto" ]
        end
        node.vm.network "forwarded_port", id: 'ssh', guest: 22, host_ip: '127.0.0.1', host: 5222, auto_correct: false, adapter: 2
    end

    #使用这个box时的网络设置例子
    # config.vm.define "dev1" do |node|
    #     node.vm.network "private_network", ip: "192.168.99.11", adapter: 1
    #     node.vm.hostname = "dev1"

    #     node.vm.provider :virtualbox do |vb|
    #       vb.customize ['modifyvm',:id, '--nic1', 'hostonly', '--nic2', 'nat']
    #       vb.customize ['modifyvm',:id, '--natpf2', "ssh,tcp,127.0.0.1,5223,,22" ] 
    #       vb.customize ['modifyvm',:id, '--macaddress1', 'auto' ]
	  #       vb.customize ['modifyvm',:id, '--macaddress2', "auto" ]
    #     end

    #     node.vm.network "forwarded_port", id: 'ssh', guest: 22, host_ip: '127.0.0.1', host: 5223, auto_correct: false, adapter: 2
    # end    
end
